
public class EvolvedPopulation {

	int[][] population1;
	int[][] population2;
	int[][] currentPopulation;
	int[][] futurePopulation;
	Integer xSize;
	Integer ySize;
	DisplayGrid displayGrid;
	
	public EvolvedPopulation(SeedPopulation seed, DisplayGrid grid)
	{
		displayGrid = grid;
		init(seed);
	}
	
	public void reset(SeedPopulation newSeed)
	{
		init(newSeed);
	}
	int[][] getCurrenPopulation()
	{
		return currentPopulation;
	}
	
	private void init(SeedPopulation seed)
	{
		xSize = new Integer(seed.getXSize());
		ySize = new Integer(seed.getYSize());
		population1 = new int[xSize][ySize];
		population2 = new int[xSize][ySize];
		for(int i=0; i<seed.getXSize();i++)
		{
			System.arraycopy(seed.seedPopulation[i], 0, population1[i], 0, seed.seedPopulation[i].length);
		}
		currentPopulation = population1;
		futurePopulation= population2;
		if(displayGrid != null)
		{
			displayGrid.updateDisplaly(currentPopulation);
		}
	}
	
	public Integer getXSize() { return xSize;}
	public Integer getYSize() { return ySize;}
	public int get(int x, int y){ return currentPopulation[x][y];}
	public void set(int x, int y, int value) { futurePopulation[x][y] = value;}
	public void swapPopulations()
	{
		int[][] tempPopulation = currentPopulation;
		currentPopulation = futurePopulation;
		futurePopulation = tempPopulation;
		if(displayGrid != null)
		{
			displayGrid.updateDisplaly(currentPopulation);
		}
	}
}
